package Function;

public class Function5 extends Function{
	private int n;
	
	public Function5(int n){ 
		// x e [0,pi]
		xmin = 0;
		xmax = Math.PI;
		
		this.n = n; 
	}
	
	public int bitLength(double accuracy){
		return n * super.bitLength(accuracy);
	}
	
	
	public double evaluate(double[] parameters) {
		// f(x, 1..n) = -sum[i=1,n](sen(Xi) * sen^20( ((i+1)*Xi^2) / pi )
		double resul = 0;
		double auxsin2;
		for (int i = 1; i <= n; i++){
			auxsin2 = ((i+1) * Math.pow(parameters[i-1], 2)) / Math.PI;
			resul += Math.sin(parameters[i-1]) * Math.pow(Math.sin(auxsin2), 20); 
		}
		return -resul;
	}

	// Getters and Setters
	public void setN(int n) { this.n = n; }
	public int getN() { return n; }
}
